package cn.wolfcode.result;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Collections;
import java.util.List;

@Getter
@Setter
@ToString
public class PageResult<T> {
    //直接从用户/数据库得到
    private int currentPage;
    private int pageSize;
    private int totalCount;
    private List<T> date;


    //需要计算得到
    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> date) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.date = date;

        //如果总数据小于等于每页条数
        if (totalCount <= pageSize) {
            this.totalPage = 1;
            this.currentPage = 1;
            this.prevPage=1;
            this.nextPage = 1;
            return;
        }
        
        //给需要计算的字段赋值
        this.totalPage=totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
        this.prevPage=currentPage-1>=1?currentPage-1:1;
        this.nextPage=currentPage+1<=totalPage?currentPage+1:totalPage;
    }
}
